Skip to main content

Install PyTorch CUDA via PDM

· One min read
pdm init

Add this to pyproject.toml

[[tool.pdm.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu121"
include_packages = ["torch", "torchvision", "torchaudio"]
exclude_packages = ["*"]
pdm add torch torchvision torchaudio
# -v: verbose
pdm install -v
note

PDM think CPU version and CUDA version are same package, if CPU version is installed, install CUDA version in another project will only install the CPU version

To remove the CPU cache package, remove the torch directory under PDM cache directory, reinstall the package does not work

Show PDM cache directory

pdm config cache_dir

Show PyTorch version

pdm run python -c "import torch; print(torch.__version__)"
2.2.0+cu121